import { Vector3 } from './three.module.js'

/*
    r: 半径
    longitude: 经度弧线
    latitude: 维度弧线
 */
export default class Geography {
    constructor(r, longitude, latitude) {
        this.r = r;
        this.longitude = longitude;
        this.latitude = latitude;
        this.position = new Vector3();

        this.updatePosi();
    }

    updatePosi() {
        const { r, longitude, latitude } = this;
        this.position.copy(new Vector3(
            r * Math.cos(latitude) * Math.cos(longitude),
            r * Math.sin(latitude),
            r * Math.cos(latitude) * -Math.sin(longitude)
        ));
    }

    getPosition(longitude, latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
        this.updatePosi();
        return this.position.clone();
    }
}